import { C_CustomsReward, C_IsTry } from "../../C_Config";
import C_App from "../../core/C_App";
import { C_NotificationConst } from "../../core/C_NotificationConst";
import C_SoundManager, { SoundName } from "../../core/utils/C_SoundManager";
import C_WinView from "./C_WinView";

const { ccclass, property } = cc._decorator;
/** 螺丝箱子 */
@ccclass
export default class C_FirstView extends C_WinView {


    @property(cc.Label)
    rewardLab: cc.Label = null;

    protected _rewardNum: number;
    initView(curIndex: number) {
        this._rewardNum = (this.getReward(curIndex) || 2)
        this.rewardLab.string = "X" + this._rewardNum;
        C_SoundManager.instance.playEffect(SoundName.Success)
        this.ani.play();
    }

    onTouchEnd() {
        if (!C_IsTry) {
            cc.systemEvent.emit("C_GameEnd", this._rewardNum)
        }
        C_App.NotificationCenter.dispatch(C_NotificationConst.BACK_CUSTOMS)
    }

    getReward(index: number) {
        for (let key in C_CustomsReward) {
            if (parseInt(key) > index) {
                return C_CustomsReward[key];
            }
        }
    }
}
